﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bizall.Dynamic.Aspect;

namespace BankSample
{
    public class ATM
    {
        dynamic bank = new Bank().AsDynamic();

        public void Run()
        {
            char key=' ';

            while (key != '3')
            {
                Console.WriteLine("============ M E N U ============");
                Console.WriteLine(" 1\tDeposit");
                Console.WriteLine(" 2\tWithdraw");
                Console.WriteLine(" 3\tExit");
                Console.WriteLine("===============================");
                Console.WriteLine("Please press item number to choose an operation.");

                key = Console.ReadKey(true).KeyChar;

                switch (key)
                {
                    case '1':
                        Depost();
                        break;
                    case '2':
                        Withdraw();
                        break;
                }
            }
        }

        private void Depost()
        {            
            Console.WriteLine("========Desposit money from bank account=============");
            Console.WriteLine("Please enter deposit amount : ");
            Console.WriteLine("==============================================");
            while (true)
            {           
                decimal amount = 0;
                string s = Console.ReadLine();
                if (decimal.TryParse(s, out amount))
                {
                    bank.Deposit(amount);
                    bank.ShowAccount();
                    break;
                }
                else
                {
                    Console.WriteLine("The amount is incorrect, please input again: ");
                }
            }
        }

        private void Withdraw()
        {
           Console.WriteLine("========Withdraw money from bank account=============");
            Console.WriteLine("Please enter withdraw amount : ");
            Console.WriteLine("==============================================");
            while (true)
            {
                string s = Console.ReadLine();
                decimal amount = 0;
                if (decimal.TryParse(s, out amount))
                {
                    bank.Withdraw(amount);
                    bank.ShowAccount();
                    break;
                }
                else
                {
                    Console.WriteLine("The amount is incorrect, please input again: ");
                }
            }
        }
    }
}
